package com.example.springkafka.consumer;

import com.example.springkafka.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

/**
 * @author szh
 */
@Component
public class HelloConsumer {
    public static final String TOPIC_NAME = "topic-test";

    @Autowired
    private UserService userService;

    //监听一个或者多个Topic
    @KafkaListener(topics = TOPIC_NAME, groupId = "TEST")
    public void handler(String message){
        System.out.println("收到消息："+message);

//        System.out.println("---------------------------------");
//
//        User user = JSON.parseObject(message, User.class);
//        System.out.println("接收到User对象：" + user);
//
//
//        // 存入对象
//        boolean save = userService.save(user);
//        System.out.println("对象保存是否成功：" + save);



    }
}

